package com.guyu.plugin.sms.exception;

import com.guyu.common.core.entity.BizResult;
import com.guyu.common.core.exception.code.ErrorCodeEnum;
import com.guyu.common.web.util.GuyuServletUtils;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.dromara.sms4j.comm.exception.SmsBlendException;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * <p> 短信异常 </p>
 *
 * @date 2024/12/27
 */
@Slf4j
@Order(Ordered.HIGHEST_PRECEDENCE)
@RestControllerAdvice
public class SmsExceptionHandler {

    @ExceptionHandler(value = SmsBlendException.class)
    public BizResult smsBlendExceptionHandler(HttpServletRequest request, SmsBlendException e) {
        log.error("[GUYU]短信异常, url:[ {} ], param:[ {} ], body:[ {} ]",
                request.getRequestURI(), GuyuServletUtils.getParams(request), GuyuServletUtils.getRequestBody(request), e);
        return BizResult.error(ErrorCodeEnum.SYSTEM_ERROR.getCode(), e.getMessage(), "sms");
    }
}
